<template>
  <view class="page-container">
    <!-- 顶部用户信息区 -->
    <view class="user-info-section">
      <view class="user-avatar-wrapper">
        <image class="user-avatar"
          :src="'https://ai-public.mastergo.com/ai/img_res/ad5d369b4d7a315e6ad9a6d106842af6.jpg'" mode="aspectFill" />
      </view>
      <view class="user-info">
        <text class="username">{{ userInfo.username || '未登录' }}</text>
        <text class="user-level">{{ userInfo.level || '点击登录' }}</text>
      </view>
      <uni-icons class="setting-icon" type="gear" size="24" />
    </view>

    <!-- 订单状态区 -->
    <view class="order-section">
      <view class="section-header">
        <text class="section-title">我的订单</text>
        <view class="view-all">
          <text class="view-all-text">查看全部</text>
          <uni-icons type="right" size="14" />
        </view>
      </view>
      <view class="order-status">
        <view v-for="(item, index) in orderStatus" :key="index" class="status-item">
          <uni-icons :type="item.icon" size="28" />
          <text class="status-text">{{ item.text }}</text>
          <text v-if="item.count" class="status-count">{{ item.count }}</text>
        </view>
      </view>
    </view>

    <!-- 功能区 -->
    <view v-for="(group, groupIndex) in functionGroups" :key="groupIndex" class="function-group">
      <view class="function-section">
        <view class="section-header">
          <text class="section-title">{{ group.title }}</text>
        </view>
        <view class="function-grid">
          <view v-for="(item, index) in group.items" :key="index" class="function-item">
            <uni-icons :type="item.icon" size="24" />
            <text class="function-text">{{ item.text }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 安全设置区 -->
    <view class="security-section">
      <view class="section-header">
        <text class="section-title">账户安全</text>
      </view>
      <view class="security-items">
        <view v-for="(item, index) in securityItems" :key="index" class="security-item">
          <view class="security-item-left">
            <uni-icons :type="item.icon" size="20" />
            <text class="security-text">{{ item.text }}</text>
          </view>
          <uni-icons type="right" size="14" color="#999" />
        </view>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
  import { ref, reactive } from 'vue';

  const currentTab = ref(3);

  const userInfo = reactive({
    username: '张三',
    level: 'VIP会员',
  });

  const orderStatus = reactive([
    { icon: 'wallet', text: '待付款', count: 2 },
    { icon: 'shop', text: '待发货', count: 1 },
    { icon: 'gift', text: '待收货', count: 0 },
    { icon: 'chat', text: '待评价', count: 3 },
    { icon: 'refresh', text: '退换/售后', count: 0 },
  ]);

  const functionGroups = reactive([
    {
      title: '我的服务',
      items: [
        { icon: 'star', text: '我的收藏' },
        { icon: 'location', text: '收货地址' },
        { icon: 'help', text: '联系客服' },
        { icon: 'notification', text: '消息中心' },
      ],
    },
    {
      title: '更多服务',
      items: [
        { icon: 'info', text: '帮助中心' },
        { icon: 'staff', text: '在线客服' },
        { icon: 'settings', text: '系统设置' },
        { icon: 'medal', text: '会员中心' },
      ],
    },
  ]);

  const securityItems = reactive([
    { icon: 'locked', text: '账户密码' },
    { icon: 'phone', text: '手机验证' },
    { icon: 'mail', text: '邮箱验证' },
  ]);


</script>

<style>
  page {
    height: 100%;
    background-color: #f5f5f5;
  }

  .page-container {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: 100rpx;
  }

  .user-info-section {
    background: linear-gradient(to right, #007AFF, #1E90FF);
    padding: 40rpx 32rpx;
    display: flex;
    align-items: center;
    position: relative;
  }

  .user-avatar-wrapper {
    width: 120rpx;
    height: 120rpx;
    border-radius: 60rpx;
    overflow: hidden;
    border: 4rpx solid rgba(255, 255, 255, 0.8);
  }

  .user-avatar {
    width: 100%;
    height: 100%;
  }

  .user-info {
    margin-left: 24rpx;
    flex: 1;
  }

  .username {
    font-size: 18px;
    color: #FFFFFF;
    font-weight: 500;
    display: block;
  }

  .user-level {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    margin-top: 8rpx;
    display: block;
  }

  .setting-icon {
    color: #FFFFFF;
  }

  .order-section,
  .function-section,
  .security-section {
    margin: 20rpx;
    background-color: #FFFFFF;
    border-radius: 16rpx;
    padding: 24rpx;
  }

  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24rpx;
  }

  .section-title {
    font-size: 16px;
    font-weight: 500;
    color: #333333;
  }

  .view-all {
    display: flex;
    align-items: center;
  }

  .view-all-text {
    font-size: 14px;
    color: #999999;
    margin-right: 8rpx;
  }

  .order-status {
    display: flex;
    justify-content: space-between;
  }

  .status-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
  }

  .status-text {
    font-size: 12px;
    color: #666666;
    margin-top: 12rpx;
  }

  .status-count {
    position: absolute;
    top: -8rpx;
    right: -8rpx;
    background-color: #FF3B30;
    color: #FFFFFF;
    font-size: 12px;
    min-width: 32rpx;
    height: 32rpx;
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6rpx;
  }

  .function-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24rpx;
  }

  .function-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .function-text {
    font-size: 12px;
    color: #666666;
    margin-top: 12rpx;
  }

  .security-items {
    display: flex;
    flex-direction: column;
  }

  .security-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24rpx 0;
    border-bottom: 1px solid #EEEEEE;
  }

  .security-item:last-child {
    border-bottom: none;
  }

  .security-item-left {
    display: flex;
    align-items: center;
  }

  .security-text {
    font-size: 14px;
    color: #333333;
    margin-left: 12rpx;
  }

  .tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100rpx;
    background-color: #FFFFFF;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #EEEEEE;
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .tab-text {
    font-size: 12px;
    color: #999999;
    margin-top: 4rpx;
  }

  .active-tab {
    color: #007AFF;
  }
</style>
